/**
* @author Ashish Gupta
* CVSSP, University of Surrey
* Copyright (c) 2010 Ashish Gupta
* All rights reserved.
*/
/**
 * 
 */
package data;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @author Ashish
 *
 */
public class ImageSet {
	protected ArrayList<String> imageName = new ArrayList<String>();
	protected ArrayList<Double> classLabel = new ArrayList<Double>();
	protected String resourceLocation = null;
	private ArrayList<Image> images;
	private VisualCodebook visualCodebook;
	
	/**
	 * @throws IOException 
	 * @throws NumberFormatException 
	 * 
	 */
	public ImageSet(String imagesetFileName, String resourceLocation) throws NumberFormatException, IOException {
		this.read(imagesetFileName, resourceLocation);
		this.setImages();
	}
	/**
	 * @param imageName the imageName to set
	 */
	public void setImageName(String imageName) {
		this.imageName.add(imageName);
	}
	/**
	 * @return the imageName
	 */
	public ArrayList<String> getImageName() {
		return imageName;
	}
	/**
	 * @param imageLabel the imageLabel to set
	 */
	public void setClassLabel(double imageLabel) {
		this.classLabel.add(imageLabel);
	}
	/**
	 * @return the imageLabel
	 */
	public ArrayList<Double> getClassLabel() {
		return classLabel;
	}
	
	public void read(String imagesetFileName, String resourceLocation) throws NumberFormatException, IOException {
		this.resourceLocation = resourceLocation;
		File file = new File(imagesetFileName);
		FileReader fr = new FileReader(file);
		BufferedReader br = new BufferedReader(fr);
		String line = null;
		while((line = br.readLine())!=null){
			String[] inLine = line.split("\t");
			this.setImageName(inLine[0]);
			this.setClassLabel(Integer.parseInt(inLine[1]));
		}
		br.close();
		fr.close();
	}
	/**
	 * @param images the images to set
	 * @throws IOException 
	 */
	public void setImages() throws IOException {
		int numImages = this.imageName.size();
		this.images = new ArrayList<Image>(numImages);
		for(int i=0;i<numImages;i++){
			Image image = new Image(this.imageName.get(i),this.classLabel.get(0),this.resourceLocation);
			this.images.add(image);
		}
		
	}
	/**
	 * @return the images
	 */
	public ArrayList<Image> getImages() {
		return images;
	}
	/**
	 * @param visualCodebook the visualCodebook to set
	 */
	public void setVisualCodebook() {
		this.visualCodebook = new VisualCodebook(this);
	}
	/**
	 * @return the visualCodebook
	 */
	public VisualCodebook getVisualCodebook() {
		return visualCodebook;
	}
	
}
